<template src="./index.html"></template>

<script>
import MedicalRecordTestTubeInfoService from "../../../../../../_services/medicalRecordTestTubeInfo.service";
export default {
  name: "TianDingPatientMeTestTubeDetailModifyComponent",
  data() {
    return {
      params: {
        TestTubeID: "0", //试管记录编号
        StartDate: "", //开始促排年月
        TransplantationDate: "", //移植完成年月
        GetOocyteNumber: "1", //取卵数
        EmbryoNumber: "1", //胚胎数
        FrozenEmbryos: "0", //冻胚
        FrozenEmbryosMove: "0", //已移冻胚
        Freshembryos: "0", //鲜胚
        FreshembryosMove: "0", //已移鲜胚
        Blastula: "0", //囊胚
        BlastulaMove: "0", //已移囊胚
        TestTubeScience: "0", //试管技术 = ['0', '1', '2']
        UserID: "0" //病患编号
      },
      showStartDate: false,
      showTransplantationDate: false,
      showGetOocyteNumber: false, //取卵数
      GetOocyteNumberList: [], //取卵数
      showEmbryoNumber: false, //胚胎数
      EmbryoNumberList: [], //胚胎数

      showFrozenEmbryos: false, //冻胚
      FrozenEmbryosList: [], //冻胚
      FrozenEmbryosMoveList: [], //已移冻胚

      showFreshembryos: false, //鲜胚
      FreshembryosList: [], //鲜胚
      FreshembryosMoveList: [], //已移鲜胚

      showBlastula: false, //囊胚
      BlastulaList: [], //囊胚
      BlastulaMoveList: [] //已移囊胚
    };
  },
  mounted() {
    let currentDate = this.utils$.getCurrentDate();
    let testDetail = JSON.parse(this.local$.getItem("tdTestDetail"));
    if (testDetail !== null) {
      this.params = testDetail;
      this.utils$.dataFormat(this.params);
    }

    this.utils$.getNumberLabel(this.GetOocyteNumberList, 1, 30, "个");
    this.utils$.getNumberLabel(this.EmbryoNumberList, 1, 30, "个");
    this.utils$.getNumberLabel(this.FrozenEmbryosList, 0, 50, "个");
    this.utils$.getNumberLabel(this.FrozenEmbryosMoveList, 0, 50, "个");
    this.utils$.getNumberLabel(this.FreshembryosList, 0, 50, "个");
    this.utils$.getNumberLabel(this.FreshembryosMoveList, 0, 50, "个");
    this.utils$.getNumberLabel(this.BlastulaList, 0, 50, "个");
    this.utils$.getNumberLabel(this.BlastulaMoveList, 0, 50, "个");
  },
  methods: {
    getStartDate(event) {
      this.params.StartDate = event;
    },
    getTransplantationDate(event) {
      this.params.TransplantationDate = event;
    },
    getGetOocyteNumber(event) {
      this.showGetOocyteNumber = false;
      this.params.EmbryoNumber = event;
    },
    getEmbryoNumber(event) {
      this.showEmbryoNumber = false;
    },
    getFrozenEmbryosMove(event) {
      this.showFrozenEmbryos = false;
    },
    getFreshembryosMove(event) {
      this.showFreshembryos = false;
    },
    getBlastulaMove(event) {
      this.showBlastula = false;
    },
    btnSubmit() {
      let user = JSON.parse(this.local$.getItem("tdUser"));
      let params = {
        TestTubeID: parseInt(this.params.TestTubeID), //试管记录编号
        StartDate: this.params.StartDate, //开始促排年月
        TransplantationDate: this.params.TransplantationDate, //移植完成年月
        GetOocyteNumber: parseInt(this.params.GetOocyteNumber), //取卵数
        EmbryoNumber: parseInt(this.params.EmbryoNumber), //胚胎数
        FrozenEmbryos: parseInt(this.params.FrozenEmbryos), //冻胚
        FrozenEmbryosMove: parseInt(this.params.FrozenEmbryosMove), //已移冻胚
        Freshembryos: parseInt(this.params.Freshembryos), //鲜胚
        FreshembryosMove: parseInt(this.params.FreshembryosMove), //已移鲜胚
        Blastula: parseInt(this.params.Blastula), //囊胚
        BlastulaMove: parseInt(this.params.BlastulaMove), //已移囊胚
        TestTubeScience: parseInt(this.params.TestTubeScience), //试管技术 = ['0', '1', '2']
        UserID: user.UserID //病患编号
      };
      if (params.TestTubeID > 0) {
        MedicalRecordTestTubeInfoService.updateTestTubeInfo(params).then(
          response => {
            if (response && response.Data > 0) {
              this.toast$("保存成功！");
            } else {
              this.toast$("保存失败！");
            }
            this.$router.push({ name: "tdPatientMeMedicalTestTubeDetail" });
          }
        );
      } else {
        MedicalRecordTestTubeInfoService.addTestTubeInfo(params).then(
          response => {
            if (response && response.Data > 0) {
              this.toast$("保存成功！");
            } else {
              this.toast$("保存失败！");
            }
            this.$router.push({ name: "tdPatientMeMedicalTestTubeDetail" });
          }
        );
      }
    }
  }
};
</script>
